package com.speedchina.permission.web.sys;

import com.speedchina.framework.base.BaseController;
import com.speedchina.framework.base.QueryModel;
import com.speedchina.framework.helper.Assert;
import com.speedchina.framework.model.R;
import com.speedchina.framework.validator.ValidatorHelper;
import com.speedchina.framework.validator.group.AddGroup;
import com.speedchina.framework.validator.group.UpdateGroup;
import com.speedchina.permission.aspect.SysLog;
import com.speedchina.permission.base.constant.SysConstant;
import com.speedchina.permission.base.i18n.I18nService;
import com.speedchina.permission.domain.sys.dto.DepartmentDTO;
import com.speedchina.permission.domain.sys.entity.Department;
import com.speedchina.permission.domain.sys.po.DepartmentPo;
import com.speedchina.permission.service.sys.DepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 组织结构 接口
 * @author hank
 * @date 2021-05-19 14:12:48
 */
@RestController
@RequestMapping("/department")
@Api(description = "系统 - 组织结构 接口")
public class DepartmentController extends BaseController<DepartmentService, Department, DepartmentDTO> {

    @Autowired
    private DepartmentService service;

    @ApiOperation("查询")
    @GetMapping("/queryAll")
    @SysLog("分页查询-组织结构")
    public R queryAll(DepartmentPo params) {
        return R.data(service.queryList(params));
    }
//    @SysLog("分页查询-组织结构")
//    public R query(Integer pageNo, Integer pageSize, DepartmentPo params) {
//        return R.page(service.queryPage(new QueryModel<>(pageNo, pageSize, params)));
//    }

    @ApiOperation("新增")
    @ApiImplicitParams({
            // @ApiImplicitParam(name = "", value = "", dataType = "String", paramType = "path")
    })
    @PostMapping
    @SysLog("新增-组织结构")
    @RequiresPermissions("sys:department:add")
    public R add(@RequestBody DepartmentPo entity) {
        ValidatorHelper.validateEntity(entity, AddGroup.class);
        return R.data(service.saveOrUpdate4AutoGenId(entity));
    }

    @ApiOperation("修改")
    @ApiImplicitParams({
            // @ApiImplicitParam(name = "id", value = "主键", dataType = "Long", paramType = "path")
    })
    @PutMapping
    @SysLog("修改-组织结构")
    @RequiresPermissions("sys:department:update")
    public R update(@RequestBody DepartmentPo entity) {
        ValidatorHelper.validateEntity(entity, UpdateGroup.class);
        return R.data(this.saveOrUpdate(entity));
    }

    @ApiOperation("批量删除")
    @DeleteMapping("/{ids}")
    @SysLog("批量删除-组织结构")
    @RequiresPermissions("sys:department:delete")
    public R delete(@PathVariable("ids") String strIds) {
        return R.data(this.deleteBatch(strIds));
    }

}
